﻿using System;
namespace WCYCReader.Drawing
{
    public class Rectangle
    {
        public int height;
        public int width;
        public int x;
        public int y;

        public Rectangle()
        {
            this.x = 0;
            this.y = 0;
            this.width = 0;
            this.height = 0;
        }

        public Rectangle(Rectangle r)
        {
            this.x = r.x;
            this.y = r.y;
            this.width = r.width;
            this.height = r.height;
        }

        public Rectangle(int width_0, int height_1)
            : this(0, 0, width_0, height_1)
        {
        }

        public Rectangle(int x_0, int y_1, int width_2, int height_3)
        {
            this.x = x_0;
            this.y = y_1;
            this.width = width_2;
            this.height = height_3;
        }

        public void add(Rectangle r)
        {
            int num = Math.Min(this.x, r.x);
            int num2 = Math.Min(this.y, r.y);
            int num3 = Math.Max((int)(this.x + this.width), (int)(r.x + r.width)) - num;
            int num4 = Math.Max((int)(this.y + this.height), (int)(r.y + r.height)) - num2;
            this.x = num;
            this.y = num2;
            this.width = num3;
            this.height = num4;
        }

        public Rectangle cloneRectangle()
        {
            return new Rectangle(this.x, this.y, this.width, this.height);
        }

        public bool contains(int x_0, int y_1)
        {
            return ((((x_0 > this.x) && (x_0 < (this.x + this.width))) && (y_1 > this.y)) && (y_1 < (this.y + this.height)));
        }

        public void expand(int tx, int ty)
        {
            this.x -= tx;
            this.y -= ty;
            this.width += 2 * tx;
            this.height += 2 * ty;
        }

        public double getHeight()
        {
            return (double)this.height;
        }

        public double getWidth()
        {
            return (double)this.width;
        }

        public double getX()
        {
            return (double)this.x;
        }

        public double getY()
        {
            return (double)this.y;
        }

        public Rectangle intersection(Rectangle r)
        {
            int x = 0;
            if ((this.x < r.x) && ((this.x + this.width) > r.x))
            {
                x = r.x;
            }
            else if ((r.x <= this.x) && ((r.x + r.width) > this.x))
            {
                x = this.x;
            }
            else
            {
                return new Rectangle(0, 0, -1, -1);
            }
            int y = 0;
            if ((this.y < r.y) && ((this.y + this.height) > r.y))
            {
                y = r.y;
            }
            else if ((r.y <= this.y) && ((r.y + r.height) > this.y))
            {
                y = this.y;
            }
            else
            {
                return new Rectangle(0, 0, -1, -1);
            }
            int num3 = Math.Min((int)(this.x + this.width), (int)(r.x + r.width));
            int num4 = Math.Min((int)(this.y + this.height), (int)(r.y + r.height));
            return new Rectangle(x, y, num3 - x, num4 - y);
        }

        public bool isEmpty()
        {
            if ((this.width > 0) && (this.height > 0))
            {
                return false;
            }
            return true;
        }

        public double minDistance(int x_0, int y_1)
        {
            if (this.contains(x_0, y_1))
            {
                return 0.0;
            }
            int num = 0;
            int num2 = 0;
            if (x_0 < this.x)
            {
                num = this.x - x_0;
            }
            else if (x_0 > (this.x + this.width))
            {
                num = x_0 - (this.x + this.width);
            }
            if (y_1 < this.y)
            {
                num2 = this.y - y_1;
            }
            else if (y_1 > (this.y + this.height))
            {
                num2 = y_1 - (this.y + this.height);
            }
            return Math.Sqrt((double)((num * num) + (num2 * num2)));
        }

        public void setLocation(int x_0, int y_1)
        {
            this.x = x_0;
            this.y = y_1;
        }

        public void translate(int tx, int ty)
        {
            this.x += tx;
            this.y += ty;
        }

        public Rectangle union(Rectangle r)
        {
            int num = Math.Min(this.x, r.x);
            int num2 = Math.Min(this.y, r.y);
            return new Rectangle(num, num2, Math.Max((int)(this.x + this.width), (int)(r.x + r.width)) - num, Math.Max((int)(this.y + this.height), (int)(r.y + r.height)) - num2);
        }
    }
}

